{extend name="public/base"}

{block name="title"}登录页面{/block}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/home/css/login.css" />
{/block}

{block name="main"}
<div class="pageControl phoneLogin">
    <div class="main-top"></div>
    <div class="msui_nav msui_navTop">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">登录</h1>
    </div>
    <div class="login-main">
        <div class="mtop30 verify">
            <div class="login-input phone ">
                <div class="weui-cell__bd">
                    <input type="text" class="weui-input input-content" placeholder="手机号" name="mobile">
                </div>
                <div class="weui-cell__ft">
                    <a href="javascript:;" class="cross"></a>
                </div>
            </div>
            <button class="weui_cell-verify js-verify">
                获取验证码
            </button>
        </div>

        <div class="login-input mtop08 resetPassword">
            <div class="weui-cell__bd">
                <input type="text" class="weui-input input-content" placeholder="验证码" name="code">
            </div>
            <div class="weui-cell__ft"></div>
        </div>
        <div class="login-title">
            <a href="javascript:;" class="cl-c81"></a>
        </div>
        <button class="login-btn cl-f" disabled="disabled">登录</button>
    </div>
</div>
{/block}

{block name="javascript"}
<script src="__STATIC__/home/js/login.js"></script>
<script>
    $(function () {
        $('.login-btn').click(function () {
            var _username = $('input[name="mobile"]').val();
            var _code = $('input[name="code"]').val();
            // 先检查帐号是否已绑定
            $.ajax({
                type : 'POST',
                url : '{:url("login/check_phone")}',
                data : {
                    mobile : _username
                },
                dataType : 'json',
                success : function (msg) {
                    console.log(msg);
                    if (msg.code == 200) {
                        send_post(_username, _code);
                    } else {
                        $.confirm("帐号已注册，是否确认将帐号绑定到该微信号", function() {
                            //点击确认后的回调函数
                            send_post(_username, _code);
                        }, function() {
                            //点击取消后的回调函数
                        });
                        //$.toptip(msg.msg, 'error');
                    }
                }
            });
        });

        function send_post(_username, _code) {
            $.ajax({
                type : 'POST',
                url : '{:url("login/index")}',
                data : {
                    mobile : _username,
                    code : _code
                },
                dataType : 'json',
                success : function (l_msg) {
                    console.log(l_msg);
                    if (l_msg.code == 200) {
                        $.toptip('登录成功', 'success');
                        setTimeout(function () {
                            window.location.href = l_msg.url;
                        }, 888)
                    } else {
                        $.toptip(l_msg.msg, 'error');
                    }
                }
            });
        }
    });
</script>
{/block}